home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / prginfo.com / PROGINFO.PAS next >
Encoding:
Pascal/Delphi Source File  |  1989-03-28  |  3.6 KB  |  109 lines

  1. {
  2.   Turbo Pascal Ver 5.0 Unit
  3.   PROGINFO.TPU
  4.   Mar 28, 1989
  5.   Programmer: Rick Housh 72466,212
  6.  
  7.   This unit provides something Borland has left out of version 5.00,
  8.   probably because it is dependent on DOS version 3.xx or higher being
  9.   the operating system.  It provides a method for a program to know its
  10.   own name.  It requires no other units to operate.  Because it needs
  11.   them itself, it also provides public functions to find the segment
  12.   of the program's environment, and the DosVersion.  Its function
  13.   DosVersion works exactly like the TP Version 5.00 DosVersion
  14.   function.  It returns a word, the low byte of which contains the
  15.   Major Dos version number, and the hi byte of which contains the
  16.   Minor Dos version number.  The ProgName function returns a String,
  17.   and the EnvSeg function returns a word containing the segment of
  18.   the environment of the current program.
  19.  
  20.   WARNING : The ProgName function will generate runtime err #255
  21.             if used on a DOS version lower then 3.00.
  22.  
  23.             Requires Borland Turbo Pascal, version 5.00
  24.  
  25.   Proper syntax examples:
  26.     StringVar := ProgName;
  27.     DosMajorByte := lo(DosVersion);
  28.     DosMinorByte := hi(Dosversion);
  29.     EnvSegWord := GetEnvSeg;
  30. }
  31.  
  32.  Unit ProgInfo;
  33.  
  34.  Interface
  35.  
  36.   Function DosVersion : Word;
  37.   Function GetEnvSeg  : Word;
  38.   Function ProgName   : String;
  39.  
  40.  Implementation
  41.  
  42.   Function DosVersion : Word;
  43.   {
  44.   Returns a word with the lo(GetDosVersion) byte holding
  45.   the Major version and hi(GetDosVersion) the minor.
  46.   This is here so this unit can be used without the DOS unit.
  47.   }
  48.   var DosV : Word;
  49.   Begin
  50.     Inline(
  51.     $B4/$30/               {    MOV    AH,$30          ; Get version func.}
  52.     $CD/$21/               {    INT    $21             ; Call DOS}
  53.     $89/$46/<DosV);        {    MOV     [BP+<DosVer],AX ; Store result }
  54.     DosVersion := DosV;    { and return it }
  55.   end;
  56.  
  57.   Function GetEnvSeg : Word;
  58.   {
  59.   Returns a word which contains the segment of the
  60.   current programs environment.
  61.   }
  62.   Begin
  63.     GetEnvSeg := memW[PrefixSeg:$002C];     { Real simple }
  64.   end;
  65.  
  66.   Function ProgName : String;
  67.     var
  68.       DosVer, EnvSeg,
  69.       i, j         : Word;
  70.       PName        : String[79];
  71.       ch           : Char;
  72.  
  73.     begin
  74.       DosVer := DosVersion;
  75.                               { If Major is 0, make it 1 }
  76.       If DosVer < 256 then DosVer := DosVer + 256;
  77.                               { If lower than three, abort with }
  78.                               { error message, and run time error }
  79.                               { 255 }
  80.       If lo(DosVer) < 3 then
  81.         begin
  82.           WriteLn('Wrong DOS version (',lo(DosVer),'.',
  83.             hi(DosVer),')');
  84.           WriteLn('Requires 3.00 or higher');
  85.           RunError(255);
  86.         end;
  87.       PName := '';             { Initialize to null string }
  88.       EnvSeg := GetEnvSeg;     { Find environment }
  89.       i := 0;                  { Initialize counter }
  90.       Repeat                   { Look through environment }
  91.         j := memW[EnvSeg:i];
  92.         inc(i);
  93.       Until j = 0000;          { Until two null bytes signal end }
  94.       i := i + 3;              { Three bytes further is our program name }
  95.       Repeat
  96.         j := mem[EnvSeg:i];
  97.         PName := PName + chr(j);    { Store the name }
  98.         inc(i);
  99.       Until mem[EnvSeg:i] = 0;      { up to zero byte at end }
  100.       for i := 1 to Length(PName) do
  101.         begin                       { Then upcase string (just in case) }
  102.           ch := UpCase(PName[i]);
  103.           PName[i] := ch;
  104.         end;
  105.       ProgName := PName;            { and return it }
  106.    end; { Function PName }
  107.  
  108.  end. { Unit ProgInfo }
  109.